package Users;

/**
 * @author Myhaylo Kotsyuruba
 * @version v.   22.02.13
 */

import java.util.Date;
public class UserTest {
    private String testName;
    private Date testDate;
    private UserAnswer[] userAnswers;
    private int userScore;
    private int maxScore;

    public UserTest(String testName, int quantityAnswers) {
        this.testName = testName;
        testDate = new Date();
        userAnswers = new UserAnswer[quantityAnswers];
        userScore = 0;
        maxScore = 0;
    }

    public void setUserAnswer(int indexUserAnswer, String userAnswer, int userScore, int maxScore) {
        userAnswers[indexUserAnswer] = new UserAnswer(userAnswer, userScore, maxScore);
        this.maxScore += maxScore;
        this.userScore += userScore;
    }

    public String toString() {
        String result = String.format("%nResult for: %s%n  from: %s", testName, testDate.toString());
        for (int index = 0; index < userAnswers.length; index++) {
            result = String.format("%s%nQuestion %d. Your answer: %s", result, index + 1, userAnswers[index].toString());
        }
        result = String.format("%s%nYOUR TOTAL SCORE ARE %d OF %d.", result, userScore, maxScore);
        return result;
    }

}
